<template>
	<view>
		<u-cell-group>
			<u-cell-item v-for="(item, index) in unEvaluates" :key="index" icon="edit-pen" :title="item.course.courseName+'——'+item.teacher.name+item.teacher.position" @click="showDialog(item.id,item.course.id,item.teacher.id)">
			</u-cell-item>
		</u-cell-group>
		<u-popup v-model="show" mode="center" width="70%" height="48%">
			<view style="margin-left: 5px;margin-right: 5px;margin-top: 8%;margin-bottom: 5%;">
				<u-form :model="evaluate" ref="uForm">
					<text style="font-size: 30rpx;color: #00bebe;">对教师和课程的评价:</text>
					<u-form-item label="" labelWidth="70px">
						<u-input v-model="evaluate.content" type="textarea" :border="true" />
					</u-form-item>
					<text style="font-size: 30rpx;color: #00bebe;">对教师和课程的评分:</text>
					<view style="text-align: center;margin-top: 5%;">
					<u-rate size=60 :allowHalf="true" v-model="evaluate.grade" :colors="colors" :icons="icons" inactive-icon="heart"></u-rate>
					</view>
				</u-form>
				<u-button :custom-style="customStyle" type="primary" @click="submit">提交</u-button>
				<u-button :custom-style="customStyle"  @click="cancel">取消</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				        colors: ['#ffc454', '#ff8c08', '#ff4902'],
				        icons: ['heart-fill'],
				customStyle: {
					marginTop: "15px",
					width:"150px",
					
				},
				show:false,
				unEvaluates:[],
				evaluate:{
					id:'',
					content:'',
					grade:5
					
				},
				teacherName:'',
				courseName:'',
				teacherId:'',
				courseId:''
		
			};
		},
		methods: {
			showDialog(id,tid,cid) {
				this.show=true;
				this.teacherId=tid;
				this.courseId=cid;
				this.evaluate.id=id;
			},
			cancel(){
				this.show=false;
				this.evaluate.content='';
				this.evaluate.grade=5;
			},
			submit(){
				this.$axios.post("/api/v1/student/evaluate",this.evaluate).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '评价成功！',
							icon: 'success'
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 1000);
					}
				});
			}
			
		},
		created() {
			let studentId=uni.getStorageSync("studentId");
			this.$axios.get("/api/v1/student/evaluate/my/"+studentId).then(res => {
				this.unEvaluates=res.data.data;
			});
		
		}
	}
</script>

<style lang="scss">

</style>
